package com.hzw.preview.day03;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Demo01 {

    public static void main(String[] args) throws Exception {
        Class<?> a = Class.forName("com.hzw.preview.day03.Cz02");
        Object o = a.newInstance();
        for (Field declaredField : a.getDeclaredFields()) {
            declaredField.setAccessible(true);
            Class<?> type = declaredField.getType();
            if (type.toString().endsWith("String")) {
                declaredField.set(o, "zhen");
            } else if (type.toString().endsWith("int")) {
                declaredField.set(o, 20);
            } else if (type.toString().endsWith("double")) {
                declaredField.set(o, 2.33);
            }
        }
        Method toString = a.getDeclaredMethod("toString");
        System.out.println(toString.invoke(o));
    }
}
